import store from "../store";
import {
	computed
} from "vue";

// 默认用户信息计算属性
const defaultUser = computed(() => {
	return store.state.userInfo;
});

export default function useLoginTodo(userInfo = defaultUser) {
	// 获取用户信息
	const checkedisLogin = () => {
		return new Promise((resolve) => {
			// 获取实际的用户信息值（处理计算属性）
			const userValue = userInfo.value !== undefined ? userInfo.value : userInfo;

			if (userValue) {
				resolve(true);
			} else {
				uni.navigateTo({
					url: '/pages/userInfo/login/login'
				});
				resolve(false);
			}
		});
	}

	return {
		checkedisLogin,
	}
}